import { getinstiution, getBranchesList } from '@/api/branches/institution'
import { jsonParse } from '@/utils/auth' // 导入反序列化数据的方法

const state = {
  branches: [],
  branchesList: []
}
const mutations = {
  getbranches(state, payload) {
    state.branches = payload
  },
  getBranchesList(state, payload) {
    state.branchesList = payload
  }
}

const actions = {
  async getbranches(context, payload) { // 获取机构详情并写到vuex里
    context.commit('getbranches', await getinstiution(payload))
  },
  async getBranchesList(context) { // 获取机构列表并反序列化写到state.branchesList里
    context.commit('getBranchesList', jsonParse((await getBranchesList()).data.data))
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations
}

